<template>
  <div>
    <div class="floor-wrap">
      <div>
        <div class="floor-item" v-for="item of floorList" :key="item.id">
          <el-button @click="floorChange(item)" :class="{ active: selectFloor == item.id }">
            {{ item.name }}
          </el-button>
        </div>
      </div>
      <div class="date-wrap">
        <div class="date-item" v-for="item of dateList" :key="item.date">
          <el-button @click="dateChange(item)" :class="{ active: nowMonthDay == item.date }">
            {{ item.date }} {{ item.week }}
          </el-button>
        </div>
      </div>
    </div>

    <div class="area-wrap">
      <el-row :gutter="24" style="width: 100%">
        <el-col :span="6" v-for="item of readingRoomList" :key="item.id">
          <el-card>
            <img v-if="item.image" :src="`//127.0.0.1:9003/${item.image}`" />
            <img v-else src="../assets/room.jpg" alt="" />
            <div class="room-name">
              {{ item.name }}
              <span class="seat-num">座位：{{ item.capacity }}</span>
            </div>
            <div class="room-time">开放时间：{{ item.openhours }} - {{ item.endhours }}</div>
            <div class="room-btn">
              <el-button type="primary" size="mini" @click="openSeat(item)">选 座</el-button>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <choose-seat ref="chooseSeat"></choose-seat>
  </div>
</template>

<script>
import request from '@/req'
import dayjs from 'dayjs'
import chooseSeat from './choose-seat.vue'
dayjs.locale('zh-cn')
export default {
  components: { chooseSeat },
  data() {
    return {
      lidId: this.$route.params.id,
      floorList: [],
      dateList: [],
      nowDate: dayjs().format('YYYY-MM-DD'),
      selectFloor: '',
      nowMonthDay: dayjs().format('MM月DD日'),
      readingRoomList: [],
    }
  },
  async created() {
    await this.getFloorListByLibId()
    this.getReadingRoomByFloorId()

    this.dateList.push({
      date: dayjs().format('MM月DD日'),
      week: '今天',
      ymd: dayjs().format('YYYY-MM-DD'),
    })
    this.dateList.push({
      date: dayjs().add(1, 'day').format('MM月DD日'),
      week: dayjs().add(1, 'day').format('ddd'),
      ymd: dayjs().add(1, 'day').format('YYYY-MM-DD'),
    })
    this.dateList.push({
      date: dayjs().add(2, 'day').format('MM月DD日'),
      week: dayjs().add(2, 'day').format('ddd'),
      ymd: dayjs().add(2, 'day').format('YYYY-MM-DD'),
    })
  },
  mounted() {},
  methods: {
    async getFloorListByLibId() {
      const res = await request.get(`/floor/getFloorListByLibId?libId=${this.lidId}`)
      this.floorList = res ? res : []
      this.selectFloor = res[0].id
    },
    async getReadingRoomByFloorId() {
      const res = await request.get(
        `/readingRoom/getReadingRoomByFloorId?floorId=${this.selectFloor}`
      )
      this.readingRoomList = res ? res : []
    },
    openSeat(room) {
      this.$refs.chooseSeat.openDia(room, this.nowDate)
    },
    dateChange(date) {
      this.nowMonthDay = date.date
      this.nowDate = date.ymd
    },
    floorChange(floor) {
      this.selectFloor = floor.id
      this.nowMonthDay = this.dateList[0].date
      this.nowDate = this.dateList[0].date.ymd
      this.getReadingRoomByFloorId()
    },
  },
}
</script>

<style scoped>
.floor-wrap {
  position: absolute;
  top: 30%;
  margin-left: 20px;
  display: flex;
  flex-direction: row;
}

.date-wrap {
  margin-left: 8px;
}
.floor-item,
.date-item {
  margin-bottom: 10px;
}
.area-wrap {
  border-left: 1px solid #ccc;
  width: calc(100vw - 250px);
  height: calc(100vh - 50px);
  margin-left: 250px;
  position: relative;
  padding: 10px;
  /* display: flex;
  flex-direction: row; */
}

.room {
  margin-left: 10px;
  width: 20%;
}

.room-name {
  font-size: 18px;
  font-weight: 600;
  margin-top: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.seat-num {
  font-size: 16px;
  font-weight: 500;
}

.room-time {
  margin-top: 10px;
}
.room-btn {
  margin-top: 10px;
  text-align: end;
}
img {
  width: 100%;
  height: 150px;
  max-width: 100%;
  max-height: 100%;
}
.active {
  color: #409eff;
  border-color: #c6e2ff;
  background-color: #ecf5ff;
}
</style>
